package com.sws.quartz.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;




import com.sws.attendance.mapper.StuAttendanceMapper;

/**
 * 学生考勤记录定时清理任务
 * 
 * @author sws
 */
@Component("stuAttendanceCleanTask")
public class StuAttendanceCleanTask {
    
    private static final Logger log = LoggerFactory.getLogger(StuAttendanceCleanTask.class);
    
    @Autowired
    private StuAttendanceMapper stuAttendanceMapper;

    /**
     * 定时清理未识别的考勤记录
     * 清理pid为默认值"未识别出"的记录
     */
    public void cleanUnrecognizedAttendances() {
        log.info("开始执行未识别考勤记录清理任务");
        try {
            // 执行逻辑删除，将pid为"未识别出"的记录标记为已删除
            int count = stuAttendanceMapper.logicalDeleteUnrecognizedAttendances();
            log.info("考勤记录清理任务完成，共逻辑删除 {} 条未识别记录", count);
        } catch (Exception e) {
            log.error("执行未识别考勤记录清理任务时发生错误", e);
        }
    }
    
    /**
     * 定时物理删除已被标记为逻辑删除的考勤记录
     * 每天执行一次，将已被标记为逻辑删除的考勤记录从数据库中彻底删除
     */
    public void physicalDeleteLogicalDeletedAttendances() {
        log.info("开始执行考勤记录物理删除任务");
        try {
            // 执行物理删除，删除所有del_flag为1的记录
            int count = stuAttendanceMapper.physicalDeleteLogicalDeletedAttendances();
            log.info("考勤记录物理删除任务完成，共清理 {} 条逻辑删除记录", count);
        } catch (Exception e) {
            log.error("执行考勤记录物理删除任务时发生错误", e);
        }
    }
} 